#include "StdAfx.h"
#include "iostream"
#include "string"
#include "windows.h"
#include "fstream"
#include "time.h"
#include "json/json.h"
using namespace std;

void randomTest()
{
	time_t t;
	srand((unsigned) time(&t));

	ifstream inReview("G:\\recsys\\yelp_training_set\\yelp_training_set_review.json");
	
	ofstream outTrain("newTrainRand.json");
	ofstream outTest("newTestRand.json");

	double tmp;
	string tmpString;
	for (int i=0;i<229907;i++)
	{
		getline(inReview,tmpString);
		tmp = (double)rand()/32767;
		if (tmp>0.9)
		{
			outTest<<tmpString<<endl;
		}
		else
		{
			outTrain<<tmpString<<endl;
		}
	}

	inReview.close();
	outTrain.close();
	outTest.close();
	
}


void setTest2None()
{
	ifstream infile("E:\\liuyqProjects\\liuyq-recsys\\recsys\\recsys\\newTestRand.json");
	ofstream outResetTest("newTestReset.json");

	time_t t;
	srand((unsigned) time(&t));

	Json::Reader reader;
	Json::Value json_object;


	int countUsers=0;
	int countBusinesses=0;

	if (!infile)
	{
		cout<<"open file error!\n"<<endl;
	}
	string json_document;
	double tmp;
	int countLine=0;
	Json::FastWriter writer;
	while(countLine<23151 && getline(infile, json_document))
	{
		tmp = (double)rand()/32767;
		if (tmp>0.7305)
		{
			outResetTest<<json_document<<endl;
		}
		else
		{
			if (!reader.parse(json_document, json_object))
			{
				cout<<"parse review.json error!\n"<<endl;
				return ;
			}

			if (tmp<=0.1317)
			{
				json_object["user_id"]="both";
				json_object["business_id"]="both";
			}
			else if (tmp<=0.1317+0.2643)
			{
				json_object["user_id"]="user";
			}
			else
				json_object["business_id"]="business";

			json_document = writer.write(json_object);

			//cout<<json_document<<endl;
			//return;
			outResetTest<<json_document;
		}
		

		countLine++;
	}

}